﻿#region Usings

using System;
using SilverBox.Extensions;

#endregion

namespace SilverBox.Logging.Listeners
{
    public class ExceptionLoggerListener : ILoggerListener
    {
        #region Implementation of ILoggerListener

        public ConditionDelegate Condition
        {
            get { return obj => obj.GetType().IsOrIsBasedOn(typeof (Exception)); }
        }

        public string GetString(object entry)
        {
            if (Condition(entry))
            {
                var ex = (Exception) entry;
                return ex.Message;
            }
            var message = string.Format("No se esperaba el tipo {0}, se esperaba System.Exception",
                                        entry.GetType().Name);

            throw new InvalidOperationException(message);
        }

        #endregion
    }
}